package com.gitee.zhanyao.test.springrestdoc.controller;

import com.gitee.zhanyao.test.springrestdoc.model.Pet;
import com.gitee.zhanyao.test.springrestdoc.model.Responses;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping(value = {"/api/pet"}, produces = {"application/json", "application/xml"})
public class PetController {

    @RequestMapping(value = {"/{petId}"}, method = {RequestMethod.GET})
    public ResponseEntity<Pet> getPetById(@PathVariable("petId") String petId) throws NotFoundException {
        Pet pet = new Pet();
        if (null != pet) {
            return Responses.ok(pet);
        }
        throw new NotFoundException(404, "Pet not found");
    }


    @RequestMapping(method = {RequestMethod.POST})
    public ResponseEntity<String> addPet(@RequestBody Pet pet) {
        return Responses.ok("SUCCESS");
    }


    @RequestMapping(method = {RequestMethod.PUT})
    public ResponseEntity<String> updatePet(@RequestBody Pet pet) {
        return Responses.ok("SUCCESS");
    }


    @RequestMapping(value = {"/findByStatus"}, method = {RequestMethod.GET})
    public ResponseEntity<List<Pet>> findPetsByStatus(@RequestParam("status") String status) {
        List<Pet> pets = new ArrayList<>();
        return Responses.ok(pets);
    }


    @RequestMapping(value = {"/findByTags"}, method = {RequestMethod.GET})
    @Deprecated
    public ResponseEntity<List<Pet>> findPetsByTags(@RequestParam("tags") String tags) {
        List<Pet> pets = new ArrayList<>();
        return Responses.ok(pets);
    }


    @RequestMapping(value = {"/findPetsHidden"}, method = {RequestMethod.GET})
    public ResponseEntity<List<Pet>> findPetsHidden(@RequestParam("tags") String tags) {
        List<Pet> pets = new ArrayList<>();
        return Responses.ok(pets);
    }

}